from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render_to_response
import datetime

from models import Product, createProducts, createTranslations, DEFAULT_LANG
#from forms import ContactForm

def current_datetime(request):
	cur_date = datetime.datetime.now()
	return render_to_response("tempTemplate.html", locals())

def default(request, lang=DEFAULT_LANG):
	createProducts()
	CURRENT_LANG = lang;
	top3Products = localize(Product.all().order('-rating').fetch(3), CURRENT_LANG)
	categorizedProducts = localize(Product.all().order('category'), CURRENT_LANG)
	
	template_values = {
	'products': categorizedProducts,
	'topProducts': top3Products,
	}
	return render_to_response('index.htm', template_values)
	
def localize(list, lang=DEFAULT_LANG):
	return [item.translate(lang) for item in list]
'''
def hours_ahead(request, pHours):
	cur_date = datetime.datetime.now()
	ar_date =  cur_date + datetime.timedelta(hours=int(pHours))
	assert False
	return HttpResponse("%s"%ar_date)
	
def contacts(request):
	if request.method == 'POST':
		form = ContactForm(request.POST);
		if form.is_valid():
			topic = form.clean_data['topic']
			message = form.clean_data['message']
			sender = form.clean_data.get('sender', 'ukr@gmail.com')
			return HttpResponseRedirect('contacts/thanks')
	else:
		form = ContactForm();
	return render_to_response('contacts_form.html', {'form':form})
'''
